'''
每组输入第一行是两个正整数N和M（0 < N <= 30000,0 < M < 5000）,分别代表学生的数目和操作的数目。
学生ID编号从1编到N。
第二行包含N个整数，代表这N个学生的初始成绩，其中第i个数代表ID为i的学生的成绩
接下来又M行，每一行有一个字符C（只取‘Q’或‘U’），和两个正整数A,B,当C为'Q'的时候, 表示这是一条询问操作，假设A<B，他询问ID从A到B（包括A,B）的学生当中，成绩最高的是多少
当C为‘U’的时候，表示这是一条更新操作，要求把ID为A的学生的成绩更改为B。

注意：输入包括多组测试数据

输入例子

5 7
1 2 3 4 5
Q 1 5
U 3 6
Q 3 4
Q 4 5
U 4 5
U 2 9
Q 1 5

输出例子：

5
6
5
9
'''
'''
while True:
    try:
        N,M = map(int,input().split(" "))
        start_sorce = list(map(int,input().split(" ")))
        obj_list = []
        max_list = []
    except:
        break
    else:       
        for ele in range(M):
            obj = list(map(str,input().split(" ")))
            obj_list.append(obj)
        for ele in obj_list:
            for data in ele:
                A = int(ele[1])
                B = int(ele[2])
                if data == "Q":
                    max_list = start_sorce[min(A,B)-1:max(A,B)]
                    print(max(max_list))
                if data == "U":
                    start_sorce[A-1] = B  
'''
'''
开发一个简单错误记录功能小模块，能够记录出错的代码所在的文件名称和行号。

处理:

1.记录最多8条错误记录，对相同的错误记录(即文件名称和行号完全匹配)只记录一条，错误计数增加；(文件所在的目录不同，文件名和行号相同也要合并)

2.超过16个字符的文件名称，只记录文件的最后有效16个字符；(如果文件名不同，而只是文件名的后16个字符和行号相同，也不要合并)

3.输入的文件可能带路径，记录文件名称不能带路径

输入例子：

E:\V1R2\product\fpgadrive.c 1325

输出例子

fpgadrive.c 1325 1
'''
'''
file_dic = dict()
while True:
    try:
        erro = [ele for ele in input().split()]
        filename = erro[0].split("\\")[-1]
        row = erro[1]
        # print(erro)
        # print(filename)
        key = filename +"/" + row
        #?print(key)
        if key in file_dic:
            file_dic[key] +=1
        else:
            file_dic[key] =1
        #?print(file_dic)
    except:
        file_dic = sorted(file_dic.items(),key = lambda item:item[1],reverse=True)
        #?print(file_dic)
        # for index,ele in file_dic.items():
        #     print(index,ele)
        for index,ele in enumerate(file_dic):
            #?print(index,ele)
            if index < 8 :
                file_name = ele[0].split("/")[0]
                if len(file_name) > 16:
                    print(file_name[-16::],ele[0].split("/")[1],ele[1])
                else:
                    print(file_name,ele[0].split("/")[1],ele[1])
            else:
                break
        break
'''
'''
扑克牌游戏大家应该都比较熟悉了，一副牌由54张组成，含3~A，2各4张，小王1张，大王1张。牌面从小到大用如下字符和字符串表示（其中，小写joker表示小王，大写JOKER表示大王）:)

3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER

输入两手牌，两手牌之间用“-”连接，每手牌的每张牌以空格分隔，“-”两边没有空格，如：4 4 4 4-joker JOKER

请比较两手牌大小，输出较大的牌，如果不存在比较关系则输出ERROR
'''

'''
poke_all = ["3","4","5","6","7","8","9","10","J","Q","K","A","2","joker","JOKER"]
poke = input().split("-")
poke_l = poke[0].split()
poke_r =poke[1].split()
if "joker JOKER" in poke:
    print("joker JOKER")
else:
    if (len(poke_l)!=4) and (len(poke_r)!=4):
        if len(poke_l) != len(poke_r):
            print("ERROR")
        else:
            if poke_all.index(poke_l[0]) > poke_all.index(poke_r[0]):
                print(poke[0])
            else:
                print(poke[1])
    elif (len(poke_l)!=4) and (len(poke_r)==4):
        print(poke[1])
    elif (len(poke_l)==4) and (len(poke_r)!=4):
        print(poke[0])
    else:
        if poke_all.index(poke_l[0]) > poke_all.index(poke_r[0]):
            print(poke[0])
        else:
            print(poke[1])
            '''

'''
#TODO
明明生成了N个1到500之间的随机整数。请你删去其中重复的数字，即相同的数字只保留一个，把其余相同的数去掉，然后再把这些数从小到大排序，按照排好的顺序输出。
'''
'''
while True:
    try:
        N_int = int(input())
        ran_list = []
        for ele in range(N_int):
            N_random = int(input())
            ran_list.append(N_random)
    except:
        break
    else:
        tem_list = []
        for data in  ran_list:
            if data not in tem_list:
                tem_list.append(data)
        tem_list.sort()
        for ele in tem_list:
            print(ele)
        break
'''

'''
#TODO
写出一个程序，接受一个十六进制的数，输出该数值的十进制表示。
'''
'''
def int_ten(num):
    int_tem = int(num,16)
    return int_tem

while True:
    try:
        str_six= input()
    except:
        break
    else:
        print(int_ten(str_six))
'''
'''
#TODO
某商店规定：三个空汽水瓶可以换一瓶汽水，允许向老板借空汽水瓶（但是必须要归还）。
小张手上有n个空汽水瓶，她想知道自己最多可以喝到多少瓶汽水。
'''

'''
def change(num):
    ch = num // 3  # 可换的瓶子
    a = num // 3 + num % 3  # 换完后的空瓶
    if a < 2:
        ch += 0
    elif a == 2:
        ch += 1
    else:
        ch += change(a)
    return int(ch)
while True:
        n = int(input())
        if n == 0:
            break
        print(change(n))
'''

'''
#TODO
输入一个字符串，求出该字符串包含的字符集合，按照字母输入的顺序输出。
'''
'''
while True:
    try:
        str = input()
        str_list = []
    except:
        break
    else:
        for ele in list(str):
            if ele not in str_list:
                str_list.append(ele)
        print("".join(data for data in str_list))
'''

'''
#TODO
有一个数组 a[N] 顺序存放 0 ~ N-1 ，要求每隔两个数删掉一个数，到末尾时循环至开头继续进行，求最后一个被删掉的数的原始下标位置。以 8 个数 (N=7) 为例 :｛ 0，1，2，3，4，5，6，7 ｝，0 -> 1 -> 2 (删除) -> 3 -> 4 -> 5 (删除) -> 6 -> 7 -> 0 (删除),如此循环直到最后一个数被删除。
'''
'''
while True:
    try:
        num = int(input())
        result = [i for i in range(num)]
        count = 1
        while len(result) != 1:
            temp = []
            for i in range(len(result)):
                if count%3!=0:
                    temp.append(result[i])
                count += 1
            result = temp
        print(result[0])
    except Exception:
        break
'''
'''
import sys
from copy import deepcopy
nums = [1,2,3,4,5,6,7,8,9]
changed_table =[]
def find_easy_position(table):
    
    smallest = 100
    m=-1
    n=-1
    sel = -1
    for i in range(9):
        for j in range(9):
            if table[i][j] == 0:
                row = table[i]
                col = [t[j] for t in table]
                block = []
                block +=table[i//3*3][j//3*3:j//3*3+3]
                block+=table[i//3*3+1][j//3*3:j//3*3+3]
                block+=table[i//3*3+2][j//3*3:j//3*3+3]
                
                sel1 = list(set(nums)- set(row))
                sel2 = list(set(nums)- set(col))
                sel3 = list(set(nums)- set(block))

                sel_ = list(set(sel1) & set(sel2) & set(sel3))
                cnt = len(sel_)

                if cnt == 0:
                    return -2,-2,-2
                if cnt < smallest:
                    smallest = cnt
                    m = i
                    n=j
                    sel = sel_
                    
    return m, n, sel

def process(table, initial_table=None):
    
    i,j,sel = find_easy_position(table)
    if i == -2:
        return -1
    if i== -1 and j == -1:
        return table

    if len(sel) == 1:
        table[i][j] = sel[0]
        return process(table, initial_table)
    else:
        for item in sel:
            ini_table = deepcopy(table)
            table[i][j] = item
            t = process(table, ini_table)
            if t == -1:
                table = deepcopy(initial_table)
                continue
            else:
                return t
    
table = []

for s in sys.stdin:
    line = []
    line = s.split(' ')
    for i in range(len(line)):
        line[i] = int(line[i])
    table.append(line)
new_table = table.copy()
t = process(new_table)

for i in range(9):
    print(t[i][0],t[i][1],t[i][2],t[i][3],t[i][4],t[i][5],t[i][6],t[i][7],t[i][8])

'''
'''
def fun(in_list, stack, out_list):
    if len(in_list) == 0 and len(stack) == 0:
        res.append(out_list)
    # 有等待进站的火车时
    if len(in_list) > 0:
        fun(in_list[1:], stack + [in_list[0]], out_list)
    # 有等待出站的列车，先出最后一列车
    if len(stack) > 0:
        fun(in_list, stack[:-1], out_list + [stack[-1]])
    return res
while True:
    try:
        n = int(input())
        order_list = list(map(int, input().split()))
        res = []      
        result = fun(order_list, [], [])
        for i in sorted(result):
            print(' '.join(map(str, i)))
    except:
        break
'''


'''
while True:
    try:
        n = int(input())
        n_list = list(map(int,input().split()))
        m = int(input())
        m_list = list(map(int,input().split()))
    except:
        break
    else:
        temp=[]
        for ele in n_list:
            temp.append(ele)
        for ele in m_list:
            temp.append(ele)
        temp = list(set(temp))
        temp.sort()
        print("".join(str(ele) for ele in temp))
        break
'''
'''
#? 从一个字符串中找到第一个不重复的字符，返回它的索引。如果不存在，则返回 -1。
def func(str):
    temp = []
    for ele in str:
        temp.append(str.count(ele))
    print(temp)
    for ele in range(len(temp)):
        if temp[ele] == 1:
            return ele
    else:
        return -1
n_str = "qwqw"
print(func(n_str))
'''

'''
#TODO 求最大连续bit数
while True:
    try:
        n_int = int(input())
        #?print(bin(n_int))
        n_bin = bin(n_int)[2:]
        n_list = sorted(n_bin.split("0"),key=lambda x:len(x),reverse=True)
        print(len(n_list[0]))
    except:
        break
'''

'''
m,n = map(int,input().split(" "))
#print(m)
#print(n)
x= 1
y =1
for ele in range(1,n+1):
    x *= (m+ele)
    y *= ele
print(int(x/y))

'''

'''
def func(x,y):
    if x < 0 or y < 0:
        return 0
    elif x == 0 or y == 0:
        return 1
    else:
        a = func(x-1, y)
        print(x)
        b = func(x, y-1)
        return a+b
 
while True:
    try:
        n, m = map(int, input().split())
        res = func(n, m)
        print(res)
    except:
        break
'''
'''
while True:
    try:
        n_int = int(input())
        n_name = list(map(str,input().split(" ")))
        count = int(input())
        count_name = list(map(str,input().split(" ")))
        n_len = 0
        n_dict = {}
        for ele in n_name:
            if ele in count_name:
                n_len += count_name.count(ele)
                n_dict[ele] = count_name.count(ele)
            elif ele not in count_name:
                n_dict[ele] = 0  
        n_dict["Invalid"] = count - n_len
        for key,value in n_dict.items():
            print(key,':',value)
    except:
        break

'''
'''
#? 动态规划初步
def L(nums,i):
    if  i==len(nums) - 1:
        return 1
    max_len = 1
    max_sum = 0
    for j in range(i+1,len(nums)):
        if nums[j] >nums[i]:
            a = L(nums,j)
            max_len = max(max_len,a+1)
    return max_len

def length_L(nums):
    return max(
    L(nums,i) for i in range(len(nums))
    )
nums = [1,5,2,4,3]
#nums=[3,-4,2,-4,2,6,-5,4]
print(length_L(nums))
'''


'''
#?算法优化
memo = {}
def L(nums,i):
    if  i in memo:
        return memo[i]
    if  i==len(nums) - 1:
        return 1
    max_len = 1
    for j in range(i+1,len(nums)):
        if nums[j] >nums[i]:
            max_len = max(max_len,L(nums,j)+1)
    memo[i] =max_len
    return max_len

def length_L(nums):
    return max(
    L(nums,i) for i in range(len(nums))
    )
nums = [1,5,2,4,3]
print(length_L(nums))

#?迭代算法
def length_L(nums):
    n = len(nums)
    L = [1] * n
    for i in reversed(range(n)):
        for j in range(i+1,n):
            if nums[j] >nums[i]:
                L[i] = max(L[i],L[j]+1)
    return max(L)
 
'''
'''
def length_L(nums):
    n = len(nums)
    L = [1] * n
    for i in reversed(range(n)):
        for j in range(i+1,n):
            if nums[j] >nums[i]:
                L[i] = max(L[i],L[j]+1)
    return max(L)

nums = [1,5,2,4,3]
print(length_L(nums))
'''

'''
import string
#print(string.ascii_letters)
while True:
    try:
        #n_str = input()
        n_str = "a8a72a6a5yy98y65ee1r2"
        for ele in n_str:
            if ele in string.ascii_letters:
                n_str = n_str.replace(ele," ")
        n_str = n_str.split(" ")

    except:
        break
    else:
        max_len = max([len(ele) for ele in n_str])
        res = ""
        for data in n_str:
            if len(data) == max_len:
                res+=data

        print(res,max_len,sep=",")
        break
'''

'''
ip = input().split(".")
if len(ip) != 4:    # 排除长度不为4部分的
    print("NO")
else:
    for i in ip:
        if (
            not i.isdigit()    # 排除不是数字的
            or (len(i) > 1 and i[0] == "0")    # 排除首位为0的
            or int(i) < 0    # 排除在[0,255]范围外的
            or int(i) > 255
        ):
            print("NO")
            break
    else:
        print("YES")
'''
'''
while True:
    try:
        def zc(k,v):
            if v%k ==0:
                v = v//k    
                k = 1
                return (str(k)+"/"+str(v))
    except:
        break
    else:
        n_str = input().split("/")
        a = int(n_str[0])
        b = int(n_str[1])
        res= []
        if b%2 ==0:
            print(zc(a,b))
        else:     
            for i in range(a,0,-1):
                if b%i==0:
                    res.append(zc(i,b))
            print("+".join(ele for ele in res))
        break
'''
'''
class Solution:
    def removeElement(self, nums:list[int], val: int) -> int:
        left, right = 0, len(nums)
        while left < right:
            if nums[left] == val:
                nums[left] = nums[right - 1]
                right -= 1
            else:
                left += 1
        return left
sol = Solution()
print(sol.removeElement([2,3,3,2],3))
'''

from typing import List
class Solution:
    """
    @param array: An array.
    @return: An interger.
    """
    def find_number(self, array: List[int]) -> int:

        # Write your code here.
        max_len = {}
        for ele in array:
            max_len[ele] = array.count(ele)
        max_list = sorted(max_len.items(), key=lambda x:(-x[1],x[0]))[0][0]
        return (max_list)
sol = Solution()
test_list = [5,5,5,1,1,2,3,3,3,4]
print(sol.find_number(test_list))
